package edu.gatech.cs2340.mule.model;

import java.io.Serializable;

/**
 * 
 * This class serves as the superclass for all of the various
 * tiles that are possible in a game of MULE (River, Plain, etc.).
 * The production rates of the tile will be handled by this class.
 * 
 * @author Keegan Nesbitt
 *
 */
public class TerrainTile implements MapTile, Serializable {	
	private static final long serialVersionUID = 1214085222257382989L;
	
	private int smithoreProductionRate;
	private int energyProductionRate;
	private int foodProductionRate;
	private String imageSource;
	private Mule mule;
	
	/**
	 * 
	 * Sets the initial amounts of the various resources the terrain tile will start with
	 * 
	 * @param smithoreProductionRate The production rate with a mule for smithore
	 * @param energyProductionRate The production rate with a mule for energy
	 * @param foodProductionRate The production rate with a mule for food
	 */
	public TerrainTile(int smithoreProductionRate, int energyProductionRate, int foodProductionRate, String imageSource) {
		this.smithoreProductionRate = smithoreProductionRate;
		this.energyProductionRate = energyProductionRate;
		this.foodProductionRate = foodProductionRate;
		this.imageSource = imageSource;
		this.mule = null;
	} // end TerrainTile constructor
	
	/**
	 * 
	 * Removes any Mules that exist on the terrain tile
	 * 
	 * @return Whether or not the MULE was removed successfully
	 */
	public boolean removeMule()	{
		if(mule == null) {
			return false;
		}
		mule = null;
		return true;
	} // end removeMule method
	
	/**
	 * 
	 * Adds a Mule to the terrain tile if possible
	 * 
	 * @param mule is the mule to add
	 * @return Whether or not the MULE was added successfully
	 */
	public boolean addMule(Mule mule) {
		if(mule != null) {
			this.mule = mule;
			return true;
		}
		else {
			return false;
		}
	} // end addMule method
	
	/**
	 * 
	 * @return The file path for the TerrainTile's image
	 */
	public String getImageSource() {
		return imageSource;
	}
	
	/**
	 * Calculates the amount of food produced by the tile
	 * @return amount of food produced
	 */
	public int calcFoodProduction() {
		if(mule == null) {
			return 0;
		}
		else if(mule.getType().equalsIgnoreCase(Mule.FOOD_TYPE)) {
			return foodProductionRate;
		}
		else {
			return 0;
		}
	}
	
	/**
	 * Calculates the amount of energy produced by the tile
	 * @return amount of energy produced
	 */
	public int calcEnergyProduction() {
		if(mule == null) {
			return 0;
		}
		else if(mule.getType().equalsIgnoreCase(Mule.ENERGY_TYPE)) {
			return energyProductionRate;
		}
		else {
			return 0;
		}
	}
	
	/**
	 * Calculates the amount of smithore produced by the tile
	 * @return amount of smithore produced
	 */
	public int calcSmithoreProduction() {
		if(mule == null) {
			return 0;
		}
		else if(mule.getType().equalsIgnoreCase(Mule.SMITHORE_TYPE)) {
			return smithoreProductionRate;
		}
		else {
			return 0;
		}
	}
	
	/**
	 * 
	 * @return whether or not the tile already has a mule
	 */
	public boolean hasMule() {
		return null != mule;
	}
} // end TerrainTile class
